import java.util.ArrayList;

import libsvm.*;



public class FeatureVector {

	private int regionRows, regionCols, width, height, offset;
	private svm_node[] nodes;
	
	public FeatureVector(int regionRows, int regionCols, int width, int height) {
		this.regionRows = regionRows;
		this.regionCols = regionCols;
		this.width = width;
		this.height = height;
		offset = regionCols*regionRows + width + height;
		nodes = new svm_node[regionRows*regionCols + 
                width + height + 
                4];
		/*
		 * vector order:
		 * density (regionRows*regioCols entries)
		 * profile (width + height entries)
		 * top half percent
		 * left half percent
		 * vertical reflect
		 * horizontal reflect
		 * aspect ratio
		 * avg dist from center
		 * endpoints	
		 * 
		 */
		
	}
	
	public void setTopHalfPercent(double percent) {
		svm_node node = new svm_node();
		node.index = offset;
		node.value = percent;
		nodes[node.index] = node;
	}
	
	public void setLeftHalfPercent(double percent) {

		svm_node node = new svm_node();
		node.index = offset + 1;
		node.value = percent;
		nodes[node.index] = node;
	}
	
	public void setVerticalReflect(double reflect) {
		svm_node node = new svm_node();
		node.index = offset + 2;
		node.value = (reflect > 0.25 ? 1 : 0);
		nodes[node.index] = node;
	}
	
	public void setHorizontalReflect(double reflect) {
		svm_node node = new svm_node();
		node.index = offset + 3;
		node.value = (reflect > 0.25 ? 1 : 0);
		nodes[node.index] = node;
	}
	
	public void setAspectRatio(float ratio) {
		svm_node node = new svm_node();
		node.index = offset + 0;
		node.value = ratio;
		nodes[node.index] = node;
	}
	
	public void setAverageDistanceFromCenter(float[] distance) {
		svm_node node = new svm_node();
		node.index = offset + 1;
		node.value = distance[0];
		nodes[node.index] = node;
	}
	
	public void setEndPoints(ArrayList<Integer> points) {
		svm_node node = new svm_node();
		node.index = offset + 2;
		node.value = points.size()/2;
		nodes[node.index] = node;
	}
	
	public void setProfiles(int[][] profiles) {
		for(int a=0; a!=2; a++) {
			int[] profile = profiles[a];
			for(int p = 0; p != profile.length; p++) {
				svm_node node = new svm_node();
				node.index = regionCols*regionRows + p + height*a;
				node.value = profile[p];
				nodes[node.index] = node;
			}
		}
	}
	
	public void setDensityPerRegion(double[][] regionDensities) {
		if (regionDensities.length != regionCols)
			return;
		if (regionDensities[0].length != regionRows)
			return;
			
		for(int i=0; i!= regionCols; i++) {
			for(int j=0; j!=regionRows; j++) {
				svm_node node = new svm_node();
				node.index = i + j*regionCols;
				node.value = regionDensities[i][j];
				nodes[node.index] = node;
			}
		}
	}
	
	public svm_node[] getNodes() {
		
		svm_node node = new svm_node();
		node.index = -1;
		nodes[nodes.length-1] = node;
		return nodes;
	}

}
